<?php

namespace app\index\controller;

use think\Controller;
use think\Request;

class Student extends Controller
{
    public function index(){
        return "此项为接口地址";
    }
    public function Likestudent($studentName){
        $student = db("student")
            ->where(['studentName', 'like', $studentName . '%'])
            ->select();
        if ($student){
            return json(["code"=>1000,"data"=>$student]);
        }else{
            return json(["code"=>1001,"data"=>"查无此人"]);
        }
    }
    public function student(){
        $student = db("student")
            ->select();
        return json(["code"=>1000,"data"=>$student]);
    }
    public function addStudent(){
        $studentName = input("get.studentName");
        $sex = input("get.sex");
        $age = input("get.age");
        $data = ["studentName"=>$studentName,"sex"=>$sex,"age"=>$age];
        $add = db("student")
            ->insert($data);
        if ($add){
            return json(["code"=>1000,"msg"=>"添加成功"]);
        }else{
            return json(["code"=>1001,"msg"=>"添加失败"]);
        }
    }
}
